<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head profile="http://gmpg.org/xfn/11">



<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>php 解壓縮zip 使用pclzip | Life["Breathing"]</title>

<meta name="generator" content="WordPress 2.7.1"> <!-- leave this for stats -->

<link rel="stylesheet" href="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/style.css" type="text/css" media="screen">
<link rel="stylesheet" href="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/print.css" type="text/css" media="print">
<link rel="alternate" type="application/rss+xml" title="Life[" breathing="" ]="" rss="" feed="" href="http://blog.hsin.tw/feed/">
<link rel="pingback" href="http://blog.hsin.tw/xmlrpc.php">

<link rel="stylesheet" href="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/shCore.css" type="text/css" media="all">
<link rel="stylesheet" href="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/shThemeDefault.css" type="text/css" media="all">
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://blog.hsin.tw/xmlrpc.php?rsd">
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://blog.hsin.tw/wp-includes/wlwmanifest.xml"> 
<meta name="generator" content="WordPress 2.7.1">


<!-- all in one seo pack 1.5.1 [278,364] -->
<meta name="keywords" content="php,zip">
<link rel="canonical" href="http://blog.hsin.tw/2008/php-pclzip/">
<!-- /all in one seo pack -->
<style type="text/css">.recentcomments a{display:inline !important;padding: 0 !important;margin: 0 !important;}</style>

<link href="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/default.css" type="text/css" rel="stylesheet"></head><body>
<div id="page">
  <div id="header">
    <div id="headerimg">
	  <h1><a href="http://blog.hsin.tw/">Life["Breathing"]</a></h1>
	  <div class="description"></div>
	</div>
	<ul id="nav">
	  <li class="page_item"><a href="http://blog.hsin.tw/" title="Home">Home</a></li>
	  	</ul>
  </div>
  <!--/header -->
  <div id="content">
  
    
    <div class="post" id="post-28">
        <h2><a href="http://blog.hsin.tw/2008/php-pclzip/" rel="bookmark" title="Permanent Link: php 解壓縮zip 使用pclzip">php 解壓縮zip 使用pclzip</a></h2>
		<span class="post-cat"><a href="http://blog.hsin.tw/category/php/" title="觀看分類「php」的全部文章" rel="category tag">php</a></span> <span class="post-calendar">2008 十二月 21st</span>
		<div class="post-content">
		<p>前幾天為了要讓人上傳壓縮檔所以咕狗了一下<br>
<span id="more-28"></span><br>
然後就找到了這個<a href="http://www.phpconcept.net/pclzip/man/en/index.php" target="_blank">pclZip</a>，是一個class，所以很好使用，include檔案就可以用了。<br>
其實他也可以壓縮檔案，只是我還用不到，所以下面講的都比較有關解壓縮。</p>
<p>這是最基本的用法：</p>
<div class="syntaxhighlighter" id="highlighter_134263"><div class="bar"><div class="toolbar"><a class="item viewSource" style="width: 16px; height: 16px;" title="view source" href="#viewSource">view source</a><div class="item copyToClipboard"><embed id="highlighter_134263_clipboard" type="application/x-shockwave-flash" title="copy to clipboard" allowscriptaccess="always" wmode="transparent" flashvars="highlighterId=highlighter_134263" menu="false" src="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/clipboard.swf" width="16" height="16"></div><a class="item printSource" style="width: 16px; height: 16px;" title="print" href="#printSource">print</a><a class="item about" style="width: 16px; height: 16px;" title="?" href="#about">?</a></div></div><div class="lines"><div class="line alt1"><code class="number">1.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="keyword">require_once</code><code class="plain">(</code><code class="string">'pclzip.lib.php'</code><code class="plain">);</code></span></span></div><div class="line alt2"><code class="number">2.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$archive</code> <code class="plain">= </code><code class="keyword">new</code> <code class="plain">PclZip(</code><code class="string">'archive.zip'</code><code class="plain">);</code></span></span></div><div class="line alt1"><code class="number">3.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$archive</code><code class="plain">-&gt;extract();</code></span></span></div></div></div>
<p>
這樣就可以把archive.zip這個檔案解壓縮到當前目錄！傷當的簡單阿！<br>
不過記得解壓縮到的目錄的權限要可以寫入，不然會卡住，我因為這個卡很久阿…很笨=..=</p>
<p>他每個method還可以加上許多的參數，可以讓壓縮檔更帥…(什麼鬼)<br>
下面是我把官網上有寫的參數都翻一下，<a href="http://www.phpconcept.net/pclzip/man/en/index.php?options" target="_blank">細節可以自己到這裡研究看看</a></p>
<table style="font-size: 12px;" width="550" bgcolor="#6e6e6e" border="1" cellpadding="3" cellspacing="1">
<tbody><tr bgcolor="#dedede">
<th width="200">參數</th>
<th width="200">引數</th>
</tr>
<tr bgcolor="#dedede">
<th colspan="2" width="400">說明</th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_PATH</td>
<td>字串</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
      要解壓縮到哪的路徑。可用於extract()、extractByIndex()。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_ADD_PATH</td>
<td>字串</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
      增加一個目錄。可用於create()、add()、extract()。(使用於create()時，是把要壓縮的檔案放進這個目錄中再壓縮，使用於extract()時，是在要解壓縮的路徑中增加此目錄，並解壓縮到此目錄中)。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_REMOVE_PATH</td>
<td>字串</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
移除部份的目錄路徑，例如原本檔案所在的目錄為aa/bb/cc/test.test.txt，但是希望壓縮或解壓縮後的路徑為cc/test.txt，
就可以使用PCLZIP_OPT_REMOVE_PATH,”aa/bb”。可用於create()、add()、extract()、
extractByIndex()。(與PCLZIP_OPT_REMOVE_ALL_PATH一起用的時候會被自動忽略) </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_REMOVE_ALL_PATH</td>
<td>–</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
移除所有檔案的目錄，所有檔案都會被解壓縮或壓縮到當前或是指定的目錄中，請注意如果有不同目錄的相同名稱檔案，使用此參數時會被覆蓋，此參數不需要引數。可用於create()、add()、extract()、extractByIndex()。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_SET_CHMOD</td>
<td>CHMOD值</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
設定解壓縮出來的檔案的CHMOD值。可用於extract()、extractByIndex()。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_BY_NAME</td>
<td>檔案名稱</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
僅解壓縮引數中所指定的檔案，檔案名稱可以用陣列或是逗號隔開表示。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_BY_EREG</td>
<td>RegEx字串</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
僅解壓縮引數中正規表達式比對檔名正確的檔案，使用php中的ereg()函式比對。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_BY_PREG</td>
<td>RegEx字串</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
僅解壓縮引數中正規表達式比對檔名正確的檔案，使用php中的preg_match()函式比對。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_BY_INDEX</td>
<td>陣列</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
僅解壓縮引數陣列中各元素所指定順序的檔案。(這個我還不太懂是照什麼順序，似乎不是照字母排)
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_EXTRACT_AS_STRING</td>
<td>–</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
將一個檔案的內容解壓縮成一個字串，通常可能用於只需要看readme檔案的情況。請注意如果一次解壓縮太多檔案，有可能會將記憶體耗盡。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_EXTRACT_IN_OUTPUT</td>
<td>–</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
將一個檔案的內容解壓縮並直接輸出(即類似直接echo此結果)。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_NO_COMPRESSION</td>
<td>–</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
將一個檔案加入此壓縮檔內，此檔案不會被壓縮，僅是放入同一個壓縮檔中。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_COMMENT</td>
<td>字串</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
建立壓縮檔時增加一個註解，如果原本已經有註解的話，將會直接覆蓋過去。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_ADD_COMMENT</td>
<td>字串</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
建立壓縮檔時增加一個註解，如果原本已經有註解的話，將會接在後面。
    </td>
</tr>
<tr bgcolor="#dedede">
<th colspan="2"></th>
</tr>
<tr bgcolor="#ffffff">
<td>PCLZIP_OPT_PREPEND_COMMENT</td>
<td>字串</td>
</tr>
<tr bgcolor="#ffffff">
<td colspan="2">
建立壓縮檔時增加一個註解，如果原本已經有註解的話，將會把原先的註解接在此字串的後面。
    </td>
</tr>
</tbody></table>
<p>
下面這些是範例，其實就跟官網的user manual內容一樣：</p>
<div class="syntaxhighlighter" id="highlighter_383272"><div class="bar"><div class="toolbar"><a class="item viewSource" style="width: 16px; height: 16px;" title="view source" href="#viewSource">view source</a><div class="item copyToClipboard"><embed id="highlighter_383272_clipboard" type="application/x-shockwave-flash" title="copy to clipboard" allowscriptaccess="always" wmode="transparent" flashvars="highlighterId=highlighter_383272" menu="false" src="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/clipboard.swf" width="16" height="16"></div><a class="item printSource" style="width: 16px; height: 16px;" title="print" href="#printSource">print</a><a class="item about" style="width: 16px; height: 16px;" title="?" href="#about">?</a></div></div><div class="lines"><div class="line alt1"><code class="number">01.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//解壓縮到extract/folder/這個目錄中</code></span></span></div><div class="line alt2"><code class="number">02.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$list</code> <code class="plain">= </code><code class="variable">$archive</code><code class="plain">-&gt;extract(PCLZIP_OPT_PATH, </code><code class="string">"extract/folder/"</code><code class="plain">);</code></span></span></div><div class="line alt1"><code class="number">03.</code><span class="content"><span class="block" style="margin-left: 0px ! important;">&nbsp;</span></span></div><div class="line alt2"><code class="number">04.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//增加這個目錄在壓縮檔中，完成以後壓縮檔裡面會有backup這個目錄，backup裡面會有這兩個檔案</code></span></span></div><div class="line alt1"><code class="number">05.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$list</code> <code class="plain">= </code><code class="variable">$archive</code><code class="plain">-&gt;create(</code><code class="string">"file.txt,image.gif"</code><code class="plain">,PCLZIP_OPT_ADD_PATH, </code><code class="string">"backup"</code><code class="plain">);</code></span></span></div><div class="line alt2"><code class="number">06.</code><span class="content"><span class="block" style="margin-left: 0px ! important;">&nbsp;</span></span></div><div class="line alt1"><code class="number">07.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//去掉部份的路徑，這裡完成後會變成test/file.txt</code></span></span></div><div class="line alt2"><code class="number">08.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$list</code> <code class="plain">= </code><code class="variable">$archive</code><code class="plain">-&gt;add(</code><code class="string">"/usr/local/user/test/file.txt"</code><code class="plain">,PCLZIP_OPT_REMOVE_PATH, </code><code class="string">"/usr/local/user"</code><code class="plain">);</code></span></span></div><div class="line alt1"><code class="number">09.</code><span class="content"><span class="block" style="margin-left: 0px ! important;">&nbsp;</span></span></div><div class="line alt2"><code class="number">10.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//把所有路徑都去掉，這個壓縮檔建立完後，裡面就只會有file.txt跟image.gif，不會有目錄了</code></span></span></div><div class="line alt1"><code class="number">11.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$list</code> <code class="plain">= </code><code class="variable">$archive</code><code class="plain">-&gt;create(</code><code class="string">"data/file.txt images/image.gif"</code><code class="plain">,PCLZIP_OPT_REMOVE_ALL_PATH);</code></span></span></div><div class="line alt2"><code class="number">12.</code><span class="content"><span class="block" style="margin-left: 0px ! important;">&nbsp;</span></span></div><div class="line alt1"><code class="number">13.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//把解壓縮出來的檔案的CHMOD設成0777</code></span></span></div><div class="line alt2"><code class="number">14.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$list</code> <code class="plain">= </code><code class="variable">$archive</code><code class="plain">-&gt;extract(PCLZIP_OPT_SET_CHMOD, 0777);</code></span></span></div><div class="line alt1"><code class="number">15.</code><span class="content"><span class="block" style="margin-left: 0px ! important;">&nbsp;</span></span></div><div class="line alt2"><code class="number">16.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//解壓縮部份的檔案，這個參數是使用檔案名稱判別</code></span></span></div><div class="line alt1"><code class="number">17.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//引數可以用下面這樣的陣列</code></span></span></div><div class="line alt2"><code class="number">18.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$rule_list</code><code class="plain">[0] = </code><code class="string">'test/aaa.txt'</code><code class="plain">;</code></span></span></div><div class="line alt1"><code class="number">19.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$rule_list</code><code class="plain">[1] = </code><code class="string">'test/ddd.txt'</code><code class="plain">;</code></span></span></div><div class="line alt2"><code class="number">20.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//或是下面這樣，一個字串中，用逗號分隔每個要解壓縮的檔案</code></span></span></div><div class="line alt1"><code class="number">21.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$rule_list</code> <code class="plain">= </code><code class="string">"test/aaa.txt,test/ddd.txt"</code><code class="plain">;</code></span></span></div><div class="line alt2"><code class="number">22.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$list</code> <code class="plain">= </code><code class="variable">$archive</code><code class="plain">-&gt;extract(PCLZIP_OPT_BY_NAME,</code><code class="variable">$rule_list</code><code class="plain">);</code></span></span></div><div class="line alt1"><code class="number">23.</code><span class="content"><span class="block" style="margin-left: 0px ! important;">&nbsp;</span></span></div><div class="line alt2"><code class="number">24.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//解壓縮部份的檔案，使用php的ereg()函式，檔案名稱有比對成功的都會被解壓縮</code></span></span></div><div class="line alt1"><code class="number">25.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$list</code> <code class="plain">= </code><code class="variable">$archive</code><code class="plain">-&gt;extract(PCLZIP_OPT_BY_EREG, </code><code class="string">"aa"</code><code class="plain">);</code></span></span></div><div class="line alt2"><code class="number">26.</code><span class="content"><span class="block" style="margin-left: 0px ! important;">&nbsp;</span></span></div><div class="line alt1"><code class="number">27.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//解壓縮部份的檔案，使用php的preg_match()函式，檔案名稱有比對成功的都會被解壓縮</code></span></span></div><div class="line alt2"><code class="number">28.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$list</code> <code class="plain">= </code><code class="variable">$archive</code><code class="plain">-&gt;extract(PCLZIP_OPT_BY_PREG, </code><code class="string">"/^bb/"</code><code class="plain">);</code></span></span></div><div class="line alt1"><code class="number">29.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//上面這兩個函式如果不懂的話，請先研究正規表示法(Regular Expression)</code></span></span></div><div class="line alt2"><code class="number">30.</code><span class="content"><span class="block" style="margin-left: 0px ! important;">&nbsp;</span></span></div><div class="line alt1"><code class="number">31.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//依照陣列中元素的索引解壓縮，可是我不太懂index啥 = =a</code></span></span></div><div class="line alt2"><code class="number">32.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$list</code> <code class="plain">= </code><code class="variable">$archive</code><code class="plain">-&gt;extract(PCLZIP_OPT_BY_INDEX, </code><code class="keyword">array</code><code class="plain">(</code><code class="string">'0-1'</code><code class="plain">,</code><code class="string">'6-7'</code><code class="plain">));</code></span></span></div><div class="line alt1"><code class="number">33.</code><span class="content"><span class="block" style="margin-left: 0px ! important;">&nbsp;</span></span></div><div class="line alt2"><code class="number">34.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//將一個檔案內容解壓縮成一個字串</code></span></span></div><div class="line alt1"><code class="number">35.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$list</code> <code class="plain">= </code><code class="variable">$archive</code><code class="plain">-&gt;extract(PCLZIP_OPT_BY_NAME, </code><code class="string">"data/readme.txt"</code><code class="plain">,PCLZIP_OPT_EXTRACT_AS_STRING);</code></span></span></div><div class="line alt2"><code class="number">36.</code><span class="content"><span class="block" style="margin-left: 0px ! important;">&nbsp;</span></span></div><div class="line alt1"><code class="number">37.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//將一個檔案內容解壓縮完後直接輸出(echo)</code></span></span></div><div class="line alt2"><code class="number">38.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$list</code> <code class="plain">= </code><code class="variable">$archive</code><code class="plain">-&gt;extract(PCLZIP_OPT_BY_NAME, </code><code class="string">"data/readme.txt"</code><code class="plain">,PCLZIP_OPT_EXTRACT_IN_OUTPUT);</code></span></span></div><div class="line alt1"><code class="number">39.</code><span class="content"><span class="block" style="margin-left: 0px ! important;">&nbsp;</span></span></div><div class="line alt2"><code class="number">40.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//將一個檔案加入一個壓縮檔中，但不會對此檔案壓縮</code></span></span></div><div class="line alt1"><code class="number">41.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$list</code> <code class="plain">= </code><code class="variable">$archive</code><code class="plain">-&gt;add(</code><code class="string">"data/file.txt"</code><code class="plain">, PCLZIP_OPT_NO_COMPRESSION);</code></span></span></div><div class="line alt2"><code class="number">42.</code><span class="content"><span class="block" style="margin-left: 0px ! important;">&nbsp;</span></span></div><div class="line alt1"><code class="number">43.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//對此壓縮檔增加一個註解，如果原本就有註解的話會被覆蓋掉</code></span></span></div><div class="line alt2"><code class="number">44.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$list</code> <code class="plain">= </code><code class="variable">$archive</code><code class="plain">-&gt;create(</code><code class="string">"data"</code><code class="plain">, PCLZIP_OPT_COMMENT, </code><code class="string">"Add a comment"</code><code class="plain">);</code></span></span></div><div class="line alt1"><code class="number">45.</code><span class="content"><span class="block" style="margin-left: 0px ! important;">&nbsp;</span></span></div><div class="line alt2"><code class="number">46.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//對此壓縮檔增加一個註解，如果原本就有註解的話會接在後面</code></span></span></div><div class="line alt1"><code class="number">47.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$list</code> <code class="plain">= </code><code class="variable">$archive</code><code class="plain">-&gt;add(</code><code class="string">"data"</code><code class="plain">, PCLZIP_OPT_ADD_COMMENT, </code><code class="string">"Add a comment after the existing one"</code><code class="plain">);</code></span></span></div><div class="line alt2"><code class="number">48.</code><span class="content"><span class="block" style="margin-left: 0px ! important;">&nbsp;</span></span></div><div class="line alt1"><code class="number">49.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="comments">//對此壓縮檔增加一個註解，如果原本就有註解的話會放在原本的註解前面</code></span></span></div><div class="line alt2"><code class="number">50.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$list</code> <code class="plain">= </code><code class="variable">$archive</code><code class="plain">-&gt;add(</code><code class="string">"data"</code><code class="plain">, PCLZIP_OPT_PREPEND_COMMENT, </code><code class="string">"Add a comment before the existing one"</code><code class="plain">);</code></span></span></div></div></div>
<p>這個是官網中extract()的範例：</p>
<div class="syntaxhighlighter" id="highlighter_663224"><div class="bar"><div class="toolbar"><a class="item viewSource" style="width: 16px; height: 16px;" title="view source" href="#viewSource">view source</a><div class="item copyToClipboard"><embed id="highlighter_663224_clipboard" type="application/x-shockwave-flash" title="copy to clipboard" allowscriptaccess="always" wmode="transparent" flashvars="highlighterId=highlighter_663224" menu="false" src="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/clipboard.swf" width="16" height="16"></div><a class="item printSource" style="width: 16px; height: 16px;" title="print" href="#printSource">print</a><a class="item about" style="width: 16px; height: 16px;" title="?" href="#about">?</a></div></div><div class="lines"><div class="line alt1"><code class="number">1.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="keyword">include</code><code class="plain">(</code><code class="string">'pclzip.lib.php'</code><code class="plain">);</code></span></span></div><div class="line alt2"><code class="number">2.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="variable">$archive</code> <code class="plain">= </code><code class="keyword">new</code> <code class="plain">PclZip(</code><code class="string">'archive.zip'</code><code class="plain">);</code></span></span></div><div class="line alt1"><code class="number">3.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="keyword">if</code> <code class="plain">(</code><code class="variable">$archive</code><code class="plain">-&gt;extract(PCLZIP_OPT_PATH, </code><code class="string">'data'</code><code class="plain">,</code></span></span></div><div class="line alt2"><code class="number">4.</code><span class="content"><code class="spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><span class="block" style="margin-left: 176px ! important;"><code class="plain">PCLZIP_OPT_REMOVE_PATH, </code><code class="string">'install/release'</code><code class="plain">) == 0) {</code></span></span></div><div class="line alt1"><code class="number">5.</code><span class="content"><code class="spaces">&nbsp;&nbsp;</code><span class="block" style="margin-left: 16px ! important;"><code class="comments">//當有錯誤的時候，可以用這個顯示錯誤訊息</code></span></span></div><div class="line alt2"><code class="number">6.</code><span class="content"><code class="spaces">&nbsp;&nbsp;</code><span class="block" style="margin-left: 16px ! important;"><code class="keyword">die</code><code class="plain">(</code><code class="string">"Error : "</code><code class="plain">.</code><code class="variable">$archive</code><code class="plain">-&gt;errorInfo(true));</code></span></span></div><div class="line alt1"><code class="number">7.</code><span class="content"><span class="block" style="margin-left: 0px ! important;"><code class="plain">}</code></span></span></div></div></div>
<p>就我剛剛的研究，目前還不行建立有密碼的壓縮檔<br>
不過還是很夠用了～ 推～</p>
<p>參考資訊：<br>
<a href="http://www.phpconcept.net/pclzip/man/en/index.php" target="_blank">PclZip</a> <br>
<a href="http://support.oss.org.tw/?q=node/147" target="_blank">PclZip 簡介與使用</a> <br>
<a href="http://wiki.oss.org.tw/index.php/Php_pclzip_1" target="_blank">TechWiki:PclZip</a> </p>
<p></p>
		
				
				
		</div>
		
		
<!-- You can start editing here. -->


   
		<!-- If comments are open, but there are no comments. -->

	 


<h3 id="respond"><a style="cursor: pointer;" onclick="document.getElementById('comment_box').style.display=(document.getElementById('comment_box').style.display=='none')?'':'none';">我要回應 »</a></h3>
<div id="comment_box" style="display: none;">

<form action="http://blog.hsin.tw/wp-comments-post.php" method="post" id="commentform">


<p><input name="author" id="author" value="" size="22" tabindex="1" type="text">
<label for="author"><strong>姓名</strong> (必須)</label></p>

<p><input name="email" id="email" value="" size="22" tabindex="2" type="text">
<label for="email"><strong>E-mail</strong> (您輸入的E-mail不會顯示於網站上) (必須)</label></p>

<p><input name="url" id="url" value="" size="22" tabindex="3" type="text">
<label for="url"><strong>URL</strong></label></p>


<p><textarea name="comment" id="comment" cols="100" rows="10" tabindex="4"></textarea></p>

<p><input name="submit" id="submit" tabindex="5" value="Submit Comment" type="submit">
<input name="comment_post_ID" value="28" type="hidden">
</p>

</form>
</div>

		
			
	</div><!--/post -->

  </div><!--/content -->

<div id="sidebar">
<ul>

  <li id="most-visited-posts" class="widget widget_wpcomstats_most_visited_posts"><h2 class="sidebartitle">熱門文章</h2><ul><li><a href="http://blog.hsin.tw/2008/javascript-vertical-carousel/" title="javascript 垂直輪播(跑馬燈、vertical carousel)">javascript 垂直輪播(跑馬燈、vert...</a> (506)</li><li><a href="http://blog.hsin.tw/2008/javascript-select-option/" title="javascript 增加表單中select的option">javascript 增加表單中select的optio...</a> (263)</li><li><a href="http://blog.hsin.tw/2008/javascript-table-add-remove-row/" title="javascript 增加及刪除table的欄位">javascript 增加及刪除table的欄位</a> (258)</li><li><a href="http://blog.hsin.tw/2009/javascript-foreach/" title="javascript中foreach的用法">javascript中foreach的用法</a> (204)</li><li><a href="http://blog.hsin.tw/2009/php-post-method-fsockopen/" title="php 傳送POST到別的URL並取得回應內容 使用fsockopen">php 傳送POST到別的URL並取得回�...</a> (185)</li></ul></li><li id="tag_cloud" class="widget widget_tag_cloud"><h2 class="sidebartitle">標籤</h2><a href="http://blog.hsin.tw/tag/%e7%80%8f%e8%a6%bd%e5%99%a8/" class="tag-link-19" title="6 篇主題" rel="tag" style="font-size: 11.8889pt;">瀏覽器</a>
<a href="http://blog.hsin.tw/tag/%e8%bb%9f%e9%ab%94/" class="tag-link-11" title="1 篇主題" rel="tag" style="font-size: 8pt;">軟體</a>
<a href="http://blog.hsin.tw/tag/bookmarklet/" class="tag-link-12" title="3 篇主題" rel="tag" style="font-size: 9.55556pt;">bookmarklet</a>
<a href="http://blog.hsin.tw/tag/checkbox/" class="tag-link-13" title="1 篇主題" rel="tag" style="font-size: 8pt;">checkbox</a>
<a href="http://blog.hsin.tw/tag/css/" class="tag-link-3" title="2 篇主題" rel="tag" style="font-size: 8.77778pt;">css</a>
<a href="http://blog.hsin.tw/tag/firefox/" class="tag-link-4" title="2 篇主題" rel="tag" style="font-size: 8.77778pt;">firefox</a>
<a href="http://blog.hsin.tw/tag/html/" class="tag-link-14" title="18 篇主題" rel="tag" style="font-size: 21.2222pt;">html</a>
<a href="http://blog.hsin.tw/tag/javascript/" class="tag-link-5" title="19 篇主題" rel="tag" style="font-size: 22pt;">javascript</a>
<a href="http://blog.hsin.tw/tag/jquery/" class="tag-link-6" title="3 篇主題" rel="tag" style="font-size: 9.55556pt;">jquery</a>
<a href="http://blog.hsin.tw/tag/php/" class="tag-link-7" title="7 篇主題" rel="tag" style="font-size: 12.6667pt;">php</a>
<a href="http://blog.hsin.tw/tag/plugin/" class="tag-link-15" title="3 篇主題" rel="tag" style="font-size: 9.55556pt;">plugin</a>
<a href="http://blog.hsin.tw/tag/rss/" class="tag-link-8" title="1 篇主題" rel="tag" style="font-size: 8pt;">rss</a>
<a href="http://blog.hsin.tw/tag/select/" class="tag-link-16" title="2 篇主題" rel="tag" style="font-size: 8.77778pt;">select</a>
<a href="http://blog.hsin.tw/tag/wordpress/" class="tag-link-9" title="1 篇主題" rel="tag" style="font-size: 8pt;">wordpress</a>
<a href="http://blog.hsin.tw/tag/xml/" class="tag-link-17" title="2 篇主題" rel="tag" style="font-size: 8.77778pt;">xml</a>
<a href="http://blog.hsin.tw/tag/zip/" class="tag-link-18" title="1 篇主題" rel="tag" style="font-size: 8pt;">zip</a></li><li id="categories-433469561" class="widget widget_categories"><h2 class="sidebartitle">分類</h2>		<ul>
			<li class="cat-item cat-item-3"><a href="http://blog.hsin.tw/category/css/" title="觀看全部分類為「css」的文章">css</a> (1)
</li>
	<li class="cat-item cat-item-4"><a href="http://blog.hsin.tw/category/firefox/" title="觀看全部分類為「firefox」的文章">firefox</a> (2)
</li>
	<li class="cat-item cat-item-5"><a href="http://blog.hsin.tw/category/javascript/" title="觀看全部分類為「javascript」的文章">javascript</a> (19)
</li>
	<li class="cat-item cat-item-6"><a href="http://blog.hsin.tw/category/jquery/" title="觀看全部分類為「jquery」的文章">jquery</a> (3)
</li>
	<li class="cat-item cat-item-7"><a href="http://blog.hsin.tw/category/php/" title="觀看全部分類為「php」的文章">php</a> (6)
</li>
	<li class="cat-item cat-item-8"><a href="http://blog.hsin.tw/category/rss/" title="觀看全部分類為「rss」的文章">rss</a> (1)
</li>
	<li class="cat-item cat-item-9"><a href="http://blog.hsin.tw/category/wordpress/" title="觀看全部分類為「wordpress」的文章">wordpress</a> (1)
</li>
	<li class="cat-item cat-item-10"><a href="http://blog.hsin.tw/category/nothing/" title="觀看全部分類為「沒什麼好說的」的文章">沒什麼好說的</a> (1)
</li>
	<li class="cat-item cat-item-11"><a href="http://blog.hsin.tw/category/%e8%bb%9f%e9%ab%94/" title="觀看全部分類為「軟體」的文章">軟體</a> (1)
</li>
		</ul>
</li>		<li id="text-433469901" class="widget widget_text">			<h2 class="sidebartitle">連結</h2>			<div class="textwidget"><a href="http://www.mymanager.tw/">mymanager</a>
<br>
</div>
		</li>		<li id="recent-posts" class="widget widget_recent_entries">			<h2 class="sidebartitle">近期文章</h2>			<ul>
						<li><a href="http://blog.hsin.tw/2009/plane/">造飛機~ </a></li>
						<li><a href="http://blog.hsin.tw/2009/bookmarklet-chinese-translate/">書籤小工具網頁簡轉繁、繁轉簡 </a></li>
						<li><a href="http://blog.hsin.tw/2009/jquery-in-action-ch3/">jQuery in Action Ch.3 筆記 </a></li>
						<li><a href="http://blog.hsin.tw/2009/jquery-in-action-ch2-creating-the-wrapped-element-set/">jQuery in Action Ch.2 筆記 </a></li>
						<li><a href="http://blog.hsin.tw/2009/javascript-ignore-ie-error/">javascript 隱藏IE左下角的錯誤提示 </a></li>
						</ul>
		</li>		<li id="text-423866741" class="widget widget_text">			<h2 class="sidebartitle">BloggerAds</h2>			<div class="textwidget"><center style="margin-top: 5px;">
<script type="text/javascript" src="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/showads.htm"></script><script language="javascript" src="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/swfobject.js"></script><script language="javascript" src="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/bafunc.js"></script><div id="BA_EXTRA" name="BA_EXTRA"></div><div id="BA_Body" name="BA_Body"><div id="dotmoreArea">  <table class="adszone"> <tbody><tr>  <td align="center"> <table class="bloggerads" id="area_title" name="area_title" cellpadding="5">  <tbody><tr> <td class="bloggerads_logo" onmouseover="window.status='BloggerAds部落客廣告';return true;" onmouseout="window.status='';return true;" onclick="adClick(web_address);"> <font size="2"><b>BloggerAds 廣告</b></font> </td> </tr> </tbody></table>  </td>  </tr> <tr> <td onmouseover="ChangeBG('0', 'over');" onmouseout="ChangeBG('0', 'out');" align="center"> <table class="bloggerads" id="area_0" name="area_0" cellpadding="5"> <tbody><tr> <td onclick="adClick('http://ad2.bloggerads.net/1759912953.iJmYSiPr/20090103000284/20090525000002/1/2489/click.aspx');" class="bloggerads_headline" onmouseover="window.status='不可思議的設計美型筆電，新登場';return true;" onmouseout="window.status='';return true;">不可思議的設計美型筆電，新登場</td>  </tr> <tr> <td onmouseover="window.status='不可思議的設計美型筆電，新登場';return true;" onmouseout="window.status='';return true;" align="center"><div id="bannerRightParent"><div id="BloggerAdsArea_0" name="BloggerAdsArea_0"><embed type="application/x-shockwave-flash" src="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/ba_145_120_090525_asus.swf" style="" id="mymovie" name="mymovie" quality="high" wmode="transparent" flashvars="getlink=http://ad2.bloggerads.net/1759912953.iJmYSiPr/20090103000284/20090525000002/1/2489/click.aspx" scale="exactfit" swliveconnect="true" allowscriptaccess="always" width="145" height="120"></div></div></td> </tr> <tr> <td onclick="adClick('http://ad2.bloggerads.net/1759912953.iJmYSiPr/20090103000284/20090525000002/1/2489/click.aspx');" class="bloggerads_text" onmouseover="window.status='不可思議的設計美型筆電，新登場';return true;" onmouseout="window.status='';return true;">智慧光源+蝶型設計，ASUS最新U系列讓生活充滿驚喜!現在就前進時尚發表會，輕身體驗U系列輕薄魅力!</td> </tr> <tr> <td onclick="adClick('http://ad2.bloggerads.net/1759912953.iJmYSiPr/20090103000284/20090525000002/1/2489/click.aspx');" class="bloggerads_more" onmouseover="window.status='不可思議的設計美型筆電，新登場';return true;" onmouseout="window.status='';return true;">更多訊息..</td> </tr> </tbody></table>  </td>  </tr> <tr> <td align="center"> <table class="bloggerads" id="area_title" name="area_title">  <tbody><tr> <td onmouseover="window.status='BloggerAds部落客廣告';return true;" onmouseout="window.status='';return true;" onclick="adClick(web_address);" style="padding: 0px;"><img src="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/bloggerads_2.gif" border="0"> </td> </tr> </tbody></table>  </td> </tr>  </tbody></table></div><div style="top: -500px; left: -500px; visibility: hidden;" id="BAImprDiv"><img src="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/impr.txt" heigh="1" onerror="this.width=0;this.height=0;" width="0" border="0" height="0"></div><div style="top: -500px; left: -500px; visibility: hidden;" id="BAWatchDiv">Impr</div></div><script language="javascript" src="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/getads3.htm"></script>
</center>

<!--blog-orbit
center style="margin-top:5px;">
<script type="text/javascript"--><!--
bo_id = "hsin.tw";
bo_width = 200;
bo_height = 400;
//-->
<!--/script>
<script src="http://www.blog-orbit.com/BOWidget.js" type="text/javascript"></script>
</center
blog-orbit--></div>
		</li>		<li id="text-423866743" class="widget widget_text">			<h2 class="sidebartitle">_go_</h2>			<div class="textwidget"><div style="margin-top: 10px;">
<div><a href="http://feeds2.feedburner.com/hsin"><img src="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/hsin.gif" style="border: 0pt none ;" alt="" width="88" height="26"></a></div>
<div>
<script type="text/javascript" src="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/button"></script>
</div>
</div></div>
		</li><li id="blog-visits" class="widget widget_wpcomstats_visits"><h2 class="sidebartitle">Page Visits</h2><ul><li>15</li></ul><a href="http://vlad.bailescu.ro/?s=search&amp;cx=partner-pub-1471777423767902%3A3w3e6z-pimt&amp;cof=FORID%3A10&amp;ie=UTF-8&amp;q=wp.com+stats+helper&amp;sa=Search#1229" title="Wordpress.com Stats Helper Plugin" style="font-size: 0.6em;">» wp.com stats helper</a></li>
 </ul>
</div>
<!--/sidebar -->  
  <div id="footer">
  </div><!--/footer -->

</div><!--/page -->



<!--credits start -->

<div id="credits">
<div class="alignleft"><span style="color: rgb(255, 255, 255);">1</span>Design by <a href="http://www.jdavidmacor.com/">j david macor.com</a>.Original <a href="http://www.ndesign-studio.com/resources/wp-themes/">WP Theme</a> &amp; <a href="http://www.ndesign-studio.com/stock-icons/">Icons</a> by <a href="http://www.ndesign-studio.com/">N.Design Studio</a></div> 

<div class="alignright"><a href="feed://http//blog.hsin.tw/feed/" class="rss">Entries RSS</a> <a href="feed://http//blog.hsin.tw/comments/feed/" class="rss">Comments RSS</a> <span class="loginout"><a href="http://blog.hsin.tw/wp-login.php">登入</a></span></div>

</div>

<!--credits end -->

<script type="text/javascript" src="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/shCore.js"></script>
<script type="text/javascript" src="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/shBrushPhp.js"></script>
<script type="text/javascript">
	SyntaxHighlighter.config.clipboardSwf = 'http://blog.hsin.tw/wp-content/plugins/syntaxhighlighter/syntaxhighlighter/scripts/clipboard.swf';
	SyntaxHighlighter.config.strings.expandSource = 'expand source';
	SyntaxHighlighter.config.strings.viewSource = 'view source';
	SyntaxHighlighter.config.strings.copyToClipboard = 'copy to clipboard';
	SyntaxHighlighter.config.strings.copyToClipboardConfirmation = 'The code is in your clipboard now';
	SyntaxHighlighter.config.strings.print = 'print';
	SyntaxHighlighter.config.strings.help = '?';
	SyntaxHighlighter.config.strings.alert = 'SyntaxHighlighter\n\n';
	SyntaxHighlighter.config.strings.noBrush = 'Can\'t find brush for: ';
	SyntaxHighlighter.config.strings.brushNotHtmlScript = 'Brush wasn\'t configured for html-script option: ';
	SyntaxHighlighter.all();
</script>
<script src="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/e-200924.js" type="text/javascript"></script>
<script type="text/javascript">
st_go({blog:'6861236',v:'ext',post:'28'});
var load_cmc = function(){linktracker_init(6861236,28,2);};
if ( typeof addLoadEvent != 'undefined' ) addLoadEvent(load_cmc);
else load_cmc();
</script><img id="wpstats" src="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/g.gif" alt="">
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script><script src="php%20%E8%A7%A3%E5%A3%93%E7%B8%AEzip%20%E4%BD%BF%E7%94%A8_files/ga.js" type="text/javascript"></script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-6753542-1");
pageTracker._trackPageview();
} catch(err) {}</script>
</body><div FirebugVersion="1.3.3" style="display: none;" id="_firebugConsole"></div></html>